﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WF.Model;
using WF.DAL;

namespace WF.BusinessObject
{
    /// <summary>
    /// WF_ApplyInstanceStateDetail业务对象
    /// </summary>
    public class WF_ApplyInstanceStateDetail : BOBase<WF_ApplyInstanceStateDetailEntity, DAL.WF_ApplyInstanceStateDetail>
    {
        #region 构造函数

        public WF_ApplyInstanceStateDetail() : base() { }
        public WF_ApplyInstanceStateDetail(WFDBDataContext DataContext) : base(DataContext) { }
        #endregion

        #region 实现基类abstract方法
        /// <summary>
        /// 实现基类的GetById abstract方法
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public override WF_ApplyInstanceStateDetailEntity GetById(string ID)
        {
            var obj = DataContext.WF_ApplyInstanceStateDetails.SingleOrDefault(o => o.RowID == ID);
            return new WF_ApplyInstanceStateDetailEntity(obj);
        }
        #endregion

        #region Public 方法
        public List<WF_ApplyInstanceStateDetailEntity> GetAll()
        {
            var target = DataContext.WF_ApplyInstanceStateDetails.ToList();
            List<WF_ApplyInstanceStateDetailEntity> result = new List<WF_ApplyInstanceStateDetailEntity>();
            foreach (var item in target)
            {
                result.Add(new WF_ApplyInstanceStateDetailEntity(item));
            }

            return result;
        }
        #endregion

        #region WF_ApplyInstanceStateDetail
        /// <summary>
        /// GetAllWF_ApplyInstanceStateDetailEntity
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public bool GetAllWF_ApplyInstanceStateDetailEntity(out List<WF_ApplyInstanceStateDetailEntity> result)
        {
            var target = DataContext.WF_ApplyInstanceStateDetails.ToList();
            result = new List<WF_ApplyInstanceStateDetailEntity>();
            foreach (var item in target)
            {
                result.Add(new WF_ApplyInstanceStateDetailEntity(item));
            }

            return true;
        }

        public List<WF_ApplyInstanceStateDetailEntity> GetApplyInstanceStateDetailByProcInstID(int procInstID)
        {
            var objs = from d in DataContext.WF_ApplyInstanceStateDetails
                       join a in DataContext.WF_ApplyInstances
                       on d.ApplyID equals a.ApplyID
                       orderby d.ModDate descending
                       where ((procInstID < 1) ? true : a.ProcInstID == procInstID)
                       select d;

            List<WF_ApplyInstanceStateDetailEntity> rt = new List<WF_ApplyInstanceStateDetailEntity>();
            foreach (var obj in objs)
            {
                rt.Add(new WF_ApplyInstanceStateDetailEntity(obj));
            }
            return rt;
        }

        ///// <summary>
        ///// GetWF_ApplyInstanceStateDetailEntityById
        ///// </summary>
        ///// <param name="p"></param>
        ///// <param name="result"></param>
        ///// <returns></returns>
        //public bool GetWF_ApplyInstanceStateDetailEntityById(string p, out WF_ApplyInstanceStateDetailEntity result)
        //{
        //    DAL.WF_ApplyInstanceStateDetail wfAppInstanceStateDetail = DataContext.WF_ApplyInstanceStateDetails.SingleOrDefault(obj => obj.RowID == p);
        //    result = new WF_ApplyInstanceStateDetailEntity(wfAppInstanceStateDetail);
        //    return true;
        //}
        ///// <summary>
        ///// add
        ///// </summary>
        ///// <param name="wF_ApplyInstanceStateDetailEntity"></param>
        ///// <returns></returns>
        //public bool Add(WF_ApplyInstanceStateDetailEntity wF_ApplyInstanceStateDetailEntity)
        //{
        //    DAL.WF_ApplyInstanceStateDetail wfAppInstanceStateDetail = new DAL.WF_ApplyInstanceStateDetail();
        //    if (wF_ApplyInstanceStateDetailEntity.ID == null || wF_ApplyInstanceStateDetailEntity.ID == string.Empty)
        //        wfAppInstanceStateDetail.RowID = System.Guid.NewGuid().ToString();
        //    else
        //        wfAppInstanceStateDetail.RowID = wF_ApplyInstanceStateDetailEntity.ID;
        //    wfAppInstanceStateDetail.ApplyID = wF_ApplyInstanceStateDetailEntity.ApplyID;
        //    wfAppInstanceStateDetail.CurWorkFlowStep = wF_ApplyInstanceStateDetailEntity.CurWorkFlowStep;
        //    wfAppInstanceStateDetail.CurAuditor = wF_ApplyInstanceStateDetailEntity.CurAuditor;
        //    wfAppInstanceStateDetail.ModDate = System.DateTime.Now;
        //    //wfAppInstanceStateDetail.ModDate = wF_ApplyInstanceStateDetailEntity.ModDate ;

        //    DataContext.WF_ApplyInstanceStateDetails.InsertOnSubmit(wfAppInstanceStateDetail);
        //    DataContext.SubmitChanges();

        //    return true;
        //}
        ///// <summary>
        ///// update
        ///// </summary>
        ///// <param name="wF_ApplyInstanceStateDetailEntity"></param>
        ///// <returns></returns>
        //public bool Update(WF_ApplyInstanceStateDetailEntity wF_ApplyInstanceStateDetailEntity)
        //{
        //    DAL.WF_ApplyInstanceStateDetail wfAppInstanceStateDetail = DataContext.WF_ApplyInstanceStateDetails.SingleOrDefault(obj => obj.RowID == wF_ApplyInstanceStateDetailEntity.ID);
        //    if (wfAppInstanceStateDetail == null)
        //        return false;

        //    wfAppInstanceStateDetail.ApplyID = wF_ApplyInstanceStateDetailEntity.ApplyID;
        //    wfAppInstanceStateDetail.CurAuditor = wF_ApplyInstanceStateDetailEntity.CurAuditor;
        //    wfAppInstanceStateDetail.CurWorkFlowStep = wF_ApplyInstanceStateDetailEntity.CurWorkFlowStep;
        //    wfAppInstanceStateDetail.ModDate = wF_ApplyInstanceStateDetailEntity.ModDate;

        //    DataContext.SubmitChanges();

        //    return true;
        //}


        ///// <summary>
        ///// delete
        ///// </summary>
        ///// <param name="p"></param>
        ///// <returns></returns>
        //public bool DeleteWF_ApplyInstanceStateDetailEntity(string p)
        //{
        //    DAL.SystemSetting sysset = DataContext.SystemSettings.SingleOrDefault(obj => obj.RowID == p);
        //    if (sysset != null)
        //    {
        //        DataContext.SystemSettings.DeleteOnSubmit(sysset);
        //        DataContext.SubmitChanges();
        //    }
        //    return true;
        //}
        #endregion
    }
}
